using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP.Classes;

namespace ERP.View
{
    public partial class viewErp_Chonmon : DevExpress.XtraEditors.XtraForm
    {
        public viewErp_Chonmon()
        {
            InitializeComponent();
        }

        public int count = 0;
        public int flag = 0;
        public cs_erp_hanghoaInfo hh = new cs_erp_hanghoaInfo();
        public cs_erp_hoadonInfo hoadon = new cs_erp_hoadonInfo();
        public cs_hmr_usersInfo user = new cs_hmr_usersInfo();

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void viewErp_Chonmon_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet("ds");
            
            ds = this.hh.Get_List();
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {
                this.count = 0;
            }
            else
            {
                this.count = ds.Tables[0].Rows.Count;
                this.grcDanhsach.DataSource = ds.Tables[0];
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            //this.Save_Info();
            //this.hoadon.ExcuteProcedure(1);
            //this.hoadon.Get_HD();
            //this.Save_CT_Info();
            //this.ban.trangthai = 3;
            //this.ban.ExcuteProcedure(2);
            //this.hoadon.trangthai = 3;
            //this.hoadon.ExcuteProcedure(2);
            //this.flag = 1;
            //this.Close();
        }

        private void Save_Info()
        {
            //this.hoadon.id_ban = this.ban.id_ban;
            //this.hoadon.trangthai = this.ban.trangthai;
            //this.hoadon.nguoiban = this.user.id_nv;
            //this.hoadon.ngayban = DateTime.Now;
            //this.hoadon.id_kh = 1;
        }
        private void Save_CT_Info()
        {
            cs_erp_chitiet_hoadonInfo ct = new cs_erp_chitiet_hoadonInfo();
            ct.id_hoadon = this.hoadon.id_hd;
            for (int i = 0; i < this.count; i++)
            {
                ct.id_monan = Convert.ToInt32(this.gridView1.GetRowCellValue(i, this.grdcID).ToString().Trim());
                ct.soluong = Convert.ToDouble(this.gridView1.GetRowCellValue(i, this.grdcSoluong).ToString().Trim());
                ct.dongia = Convert.ToDouble(this.gridView1.GetRowCellValue(i, this.grdcDongia).ToString().Trim());
                ct.thanhtien = ct.soluong * ct.dongia;
                if (ct.soluong > 0)
                {
                    ct.ExcuteProcedure(1);
                }
            }
        }
    }
}